<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            box-sizing: border-box;
        }

        .div1 {
            text-align: center;
            line-height: 100px;
        }

        .outter-box {
            width: 300px;
            height: 100px;
            border: 1px solid #000;
        }

        .inner-box {
            width: 20px;
            height: 20px;
            background-color: #f00;
        }

        .flex-box {
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .modal {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        .margin-box {
            position: absolute;
            left: 0;
            top: 0;
            bottom: 0;
            right: 0;
            margin: auto;
        }

        .margin-outter {
            position: relative;;
        }
    </style>
</head>

<body>
    <ul>
        <li>text-align:center、line-height=height，缺点：文字只能有一行</li>
        <li>弹性盒子：最常用</li>
        <li>使用定位（绝对定位或者固定定位）+位移：常用于模态窗口，在屏幕中间显示</li>
        <li>定位（绝对定位，left,top,bottom,right都为0）+margin（margin: auto）：</li>
    </ul>
    <!-- 缺点：文字只能有一行 -->
    <div class="outter-box div1">
        text-align:center、line-height=height
    </div>

    <div class="outter-box flex-box">
        <div class="inner-box"></div>
    </div>

    <div class="outter-box modal">
    </div>
    <div class="outter-box margin-outter">
        <div class="inner-box margin-box"></div>
    </div>
</body>

</html>